class UploadsController < ApplicationController

  def create
    image = Image.new
    image.image = "/uploads/#{upload(params[:file])}"
    image.save
    respond_to do |format|
      format.json {
        render json: {id: image.id, path: image.image}
      }
    end
  end

  private

  def upload(upload_file)
    File.open(Rails.root.join('public', 'uploads', upload_file.original_filename), 'wb') do |file|
        file.write(upload_file.read)
     end
     upload_file.original_filename
  end
end
